diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-25 03:28:27 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-25 03:28:27 +0000 |
| commit | 4c2d4c235bd80368e31cae9c375e9a585f6a6844 (patch) | |
| tree | 7fd1847e1e30ef2052281453bfb7a1c45ac6627a /app/api/data-room/[projectId]/share/route.ts | |
| parent | f69e125f1a0b47bbc22e2784208bf829bcdd24f8 (diff) | |
(대표님) archiver 추가, 데이터룸구현
Diffstat (limited to 'app/api/data-room/[projectId]/share/route.ts')
| -rw-r--r-- | app/api/data-room/[projectId]/share/route.ts | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/app/api/data-room/[projectId]/share/route.ts b/app/api/data-room/[projectId]/share/route.ts new file mode 100644 index 00000000..9b27d9fc --- /dev/null +++ b/app/api/data-room/[projectId]/share/route.ts @@ -0,0 +1,79 @@ +// app/api/files/[projectId]/share/route.ts +import { NextRequest, NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth/next'; +import { authOptions } from '@/app/api/auth/[...nextauth]/route' +import { FileService, type FileAccessContext } from '@/lib/services/fileService'; +import { z } from 'zod'; + +const createShareSchema = z.object({ + fileId: z.string().uuid(), + accessLevel: z.enum(['view_only', 'view_download']).optional(), + password: z.string().optional(), + expiresAt: z.string().datetime().optional(), + maxDownloads: z.number().positive().optional(), + sharedWithEmail: z.string().email().optional(), +}); + +// 공유 링크 생성 +export async function POST( + request: NextRequest, + { params }: { params: { projectId: string } } +) { + try { + const session = await getServerSession(authOptions); + if (!session?.user) { + return NextResponse.json({ error: '인증이 필요합니다' }, { status: 401 }); + } + + const body = await request.json(); + const validatedData = createShareSchema.parse(body); + + const context: FileAccessContext = { + userId: session.user.id, + userDomain: session.user.domain || 'partners', + userEmail: session.user.email, + ipAddress: request.ip || request.headers.get('x-forwarded-for') || undefined, + userAgent: request.headers.get('user-agent') || undefined, + }; + + const fileService = new FileService(); + const shareToken = await fileService.createShareLink( + validatedData.fileId, + { + ...validatedData, + expiresAt: validatedData.expiresAt + ? new Date(validatedData.expiresAt) + : undefined, + }, + context + ); + + const shareUrl = `${process.env.NEXT_PUBLIC_APP_URL}/shared/${shareToken}`; + + return NextResponse.json({ + shareToken, + shareUrl, + success: true + }); + } catch (error) { + if (error instanceof z.ZodError) { + return NextResponse.json( + { error: '잘못된 요청 데이터', details: error.errors }, + { status: 400 } + ); + } + + if (error instanceof Error && error.message.includes('권한')) { + return NextResponse.json( + { error: error.message }, + { status: 403 } + ); + } + + console.error('공유 링크 생성 오류:', error); + return NextResponse.json( + { error: '공유 링크 생성에 실패했습니다' }, + { status: 500 } + ); + } +}
\ No newline at end of file |
